﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using NetSysData;

namespace BladeTecWebApplication
{
	public partial class AddApplicant : System.Web.UI.Page
	{
		protected void Page_Load(object sender, EventArgs e)
		{
			if (!Page.IsPostBack)
			{
				NetSysData.NetSysData data = new NetSysData.NetSysData();
				POSITION[] positions = data.GetPositions();

				ddlPositions.Items.Add(new ListItem("Select ...", ""));
				foreach (POSITION position in positions)
				{
					string hire_date = DateTime.Parse(position.HIRE_DATE.ToString()).ToString("d");
					ddlPositions.Items.Add(new ListItem(position.POSITION_TITLE + " (" + hire_date + ")", position.POSITION_ID.ToString()));
				}
			}
		}

		protected void btnAddApplicant_Click(object sender, EventArgs e)
		{
			NetSysData.NetSysData data = new NetSysData.NetSysData();
			APPLICANT applicant = new APPLICANT();
			string key = "";

			applicant.FIRST_NAME = txtFirstName.Text;
			applicant.LAST_NAME = txtLastName.Text;
			applicant.PHONE_NUMBER = txtPhone.Text;
			applicant.EMAIL = txtEmail.Text;
			applicant.POSITION_ID = Convert.ToInt32(ddlPositions.SelectedValue);
			applicant.INTERVIEW_DATE = DateTime.Parse(interviewDate.Value);

			key = data.AddApplicant(applicant);
			clearForm();

			lblFirstName.Text = applicant.FIRST_NAME;
			lblLastName.Text = applicant.LAST_NAME;
			lblPosition.Text = ddlPositions.SelectedItem.Text;
			lblQuizDate.Text = interviewDate.Value;
			lblKey.Text = key.ToUpper();

			addConfirmationForm.Visible = true;
			newApplicantForm.Visible = false;
		}

		private void clearForm()
		{
			txtEmail.Text = "";
			txtLastName.Text = "";
			txtPhone.Text = "";
			txtFirstName.Text = "";
		}
	}
}